package main

import (
	"fmt"
)

func main() {
	fmt.Println("--变量--")
	//方法1：声明一个变量，默认初始值
	var a int
	fmt.Println("a = ", a)
	fmt.Printf("a的类型是：%T \n", a)
	var name string
	fmt.Println("name = ", name)
	fmt.Printf("name的类型是：%T \n", name)
	var T bool
	fmt.Println("T = ", T)
	fmt.Printf("T的类型是：%T \n", T)
	fmt.Println("----------------")
	var num int
	fmt.Println("num = ", num)

	fmt.Println("方法二")
	//方法2：声明变量，并初始化值
	var b int = 100
	fmt.Printf("b = %d, type of b = %T \n", b, b)
	var bb string = "从0到Go语言微服务架构师"
	fmt.Printf("bb = %s, type of bb = %T \n", bb, bb)

	var age int = 37
	fmt.Printf("age = %d, type of age = %T \n", age, age)
	var work string = "Go语言工程师"
	fmt.Printf("work = %s, type of work = %T \n", work, work)

	var price float64 = 99.99
	fmt.Printf("price = %f, type of price = %T \n", price, price)
	var bookName string = "百年孤独"
	fmt.Printf("bookName = %s, type of bookName = %T \n", bookName, bookName)
	fmt.Println("----------------")
	var numT int = 37
	fmt.Println("This is my age ", numT)

	fmt.Println("方法三")
	//方法3：在初始化的时候，可以省去数据类型，通过值去自动匹配当前变量的数据类型
	var c = 100
	fmt.Printf("c = %d, type of c = %T \n", c, c)
	var cc = "Go语言微服务核心"
	fmt.Printf("cc = %s, type of cc = %T \n", cc, cc)

	var phonePrice = 5999
	fmt.Printf("phonePrice = %d, type of phonePrice = %T \n", phonePrice, phonePrice)
	var phoneName = "apple"
	fmt.Printf("phoneName = %s, type of phoneName = %T \n", phoneName, phoneName)

	var money = 7500.00
	fmt.Printf("money = %f, type of money = %T \n", money, money)
	var myNane = "Go语言精通，要好好的对待"
	fmt.Printf("myName = %s, type of myName = %T \n", myNane, myNane)
	fmt.Println("----------------")
	var name01 = "white"
	fmt.Printf("name = %s, type of name01 = %T \n", name01, name01)

	fmt.Println("方法四")
	sex := "男"
	fmt.Printf("sex = %s ,type of sex = %T \n", sex, sex)
	ageOld := 36
	fmt.Printf("ageOld = %d, type of ageOld = %T \n", ageOld, ageOld)
	priceOne := 99.02
	fmt.Printf("priceOne = %f, type of priceOne = %T \n", priceOne, priceOne)

	//方法4：（常用的方法）省去var关键字，使用 := ,即推导数据类型又赋值
	//注：短声明是在函数或方法内部使用，不支持全局变量声明
	e := 100
	fmt.Printf("e = %d,  e的类型是：  %T \n", e, e)
	f := "Go语言微服务架构师"
	fmt.Printf("f = %s,  f的类型是： %T \n", f, f)

	fmt.Println("声明多个变量")
	var n1, n2, n3 int
	fmt.Println(n1, n2, n3)

	var n4, nameXh, n5 = 10, "small red", 3.1415
	fmt.Printf("n4 = %d, type of n4 = %T \n", n4, n4)
	fmt.Printf("nameXh = %s, type of nameXh = %T \n", nameXh, nameXh)
	fmt.Printf("n5 = %f, type of n5 = %T \n", n5, n5)

	n6, height := 6.98, 37.5
	fmt.Printf("n6 = %f, type of n6 = %T \n", n6, n6)
	fmt.Printf("height = %f, type of height = %T \n", height, height)
	numTwo, numThree := 22.3615, 69.4511
	fmt.Printf("numTwo = %f, type of numTwo = %T \n", numTwo, numTwo)
	fmt.Printf("numThree = %f, type of numThree = %T \n", numThree, numThree)

	//声明多个变量
	fmt.Println()
	var xx, yy int = 100, 200
	fmt.Printf("xx = %d, type of xx = %T \n", xx, xx)
	fmt.Printf("yy = %d, type of yy = %T \n", yy, yy)
	var kk, wx = 300, "Go语言微服务架构师"
	fmt.Printf("kk = %d, type of kk = %T \n", kk, kk)
	fmt.Printf("wx = %s, type of wx = %T \n", wx, wx)

	var (
		nn int  = 100
		mm bool = true
	)

	fmt.Printf("nn = %d, type of nn = %T \n", nn, nn)
	fmt.Printf("mm = %t, type of mm = %T \n", mm, mm)
}
